#coding:utf-8

from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice
import os
#连接设备(等待时间，‘版本号’)
device = MonkeyRunner.waitForConnection(1,'650e970b7d93')

result = device.takeSnapshot()

result1= result.getSubImage((470,309,108,30))
result2= result.getSubImage((697,309,108,30))
result3= result.getSubImage((935,309,108,30))
result4= result.getSubImage((470,388,108,30))
result5= result.getSubImage((697,388,108,30))
result6= result.getSubImage((935,388,108,30))
result7= result.getSubImage((470,466,108,30))
result8= result.getSubImage((697,466,108,30))
result9= result.getSubImage((935,466,108,30))


result1.writeToFile('D:\\python_file\\monkeyrunner\\1.png','png')
result2.writeToFile('D:\\python_file\\monkeyrunner\\2.png','png')
result3.writeToFile('D:\\python_file\\monkeyrunner\\3.png','png')
result4.writeToFile('D:\\python_file\\monkeyrunner\\4.png','png')
result5.writeToFile('D:\\python_file\\monkeyrunner\\5.png','png')
result6.writeToFile('D:\\python_file\\monkeyrunner\\6.png','png')
result7.writeToFile('D:\\python_file\\monkeyrunner\\7.png','png')
result8.writeToFile('D:\\python_file\\monkeyrunner\\8.png','png')
result9.writeToFile('D:\\python_file\\monkeyrunner\\9.png','png')

code1=os.popen("python D:\python_file\ocr_test\png_1.py")
code2=os.popen("python D:\python_file\ocr_test\png_2.py")
code3=os.popen("python D:\python_file\ocr_test\png_3.py")
code4=os.popen("python D:\python_file\ocr_test\png_4.py")
code5=os.popen("python D:\python_file\ocr_test\png_5.py")
code6=os.popen("python D:\python_file\ocr_test\png_6.py")
code7=os.popen("python D:\python_file\ocr_test\png_7.py")
code8=os.popen("python D:\python_file\ocr_test\png_8.py")
code9=os.popen("python D:\python_file\ocr_test\png_9.py")




print(code1.read())
print(code2.read())
print(code3.read())
print(code4.read())
print(code5.read())
print(code6.read())
print(code7.read())
print(code8.read())
print(code9.read())
print('########################')
'''
while a!='王耆96区':
    device.touch(645,465,'DOWN_AND_UP')
    device.drag((645,465),(645,400),1)
    MonkeyRunner.sleep(0.2)
    result = device.takeSnapshot()
    result= result.getSubImage((470,309,108,30))
    result.writeToFile('D:\\python_file\\monkeyrunner\\test4.png','png')
    code1=os.popen("python D:\python_file\ocr_test\png.py")
    print(code1.read())
elif a=='王耆96区':
    print('ok2')
else :
    print(error)

'''
count=0

while 1:
    if code1.read()=='王耆96区':
        break
    else:
        while 60<50:
            while (count < 40):
                device.drag((645,465),(645,100),0.1,10)
                count = count + 1
                print('end')

                
            MonkeyRunner.sleep(2)
                
            device.drag((645,300),(645,500),0.1,10)
            result = device.takeSnapshot()
            
            result1= result.getSubImage((470,309,108,30))
            result2= result.getSubImage((697,309,108,30))
            result3= result.getSubImage((935,309,108,30))
            result4= result.getSubImage((470,388,108,30))
            result5= result.getSubImage((697,388,108,30))
            result6= result.getSubImage((935,388,108,30))
            result7= result.getSubImage((470,466,108,30))
            result8= result.getSubImage((697,466,108,30))
            result9= result.getSubImage((935,466,108,30))


            result1.writeToFile('D:\\python_file\\monkeyrunner\\1.png','png')
            result2.writeToFile('D:\\python_file\\monkeyrunner\\2.png','png')
            result3.writeToFile('D:\\python_file\\monkeyrunner\\3.png','png')
            result4.writeToFile('D:\\python_file\\monkeyrunner\\4.png','png')
            result5.writeToFile('D:\\python_file\\monkeyrunner\\5.png','png')
            result6.writeToFile('D:\\python_file\\monkeyrunner\\6.png','png')
            result7.writeToFile('D:\\python_file\\monkeyrunner\\7.png','png')
            result8.writeToFile('D:\\python_file\\monkeyrunner\\8.png','png')
            result9.writeToFile('D:\\python_file\\monkeyrunner\\9.png','png')

            code1=os.popen("python D:\python_file\ocr_test\png_1.py")
            code2=os.popen("python D:\python_file\ocr_test\png_2.py")
            code3=os.popen("python D:\python_file\ocr_test\png_3.py")
            code4=os.popen("python D:\python_file\ocr_test\png_4.py")
            code5=os.popen("python D:\python_file\ocr_test\png_5.py")
            code6=os.popen("python D:\python_file\ocr_test\png_6.py")
            code7=os.popen("python D:\python_file\ocr_test\png_7.py")
            code8=os.popen("python D:\python_file\ocr_test\png_8.py")
            code9=os.popen("python D:\python_file\ocr_test\png_9.py")




            print(code1.read())
            print(code2.read())
            print(code3.read())
            print(code4.read())
            print(code5.read())
            print(code6.read())
            print(code7.read())
            print(code8.read())
            print(code9.read())
            print('######################')







        else:
            device.drag((544,465),(544,100),0.1,10)

            
            result = device.takeSnapshot()
            
            result1= result.getSubImage((470,309,108,30))
            result2= result.getSubImage((697,309,108,30))
            result3= result.getSubImage((935,309,108,30))
            result4= result.getSubImage((470,388,108,30))
            result5= result.getSubImage((697,388,108,30))
            result6= result.getSubImage((935,388,108,30))
            result7= result.getSubImage((470,466,108,30))
            result8= result.getSubImage((697,466,108,30))
            result9= result.getSubImage((935,466,108,30))


            result1.writeToFile('D:\\python_file\\monkeyrunner\\1.png','png')
            result2.writeToFile('D:\\python_file\\monkeyrunner\\2.png','png')
            result3.writeToFile('D:\\python_file\\monkeyrunner\\3.png','png')
            result4.writeToFile('D:\\python_file\\monkeyrunner\\4.png','png')
            result5.writeToFile('D:\\python_file\\monkeyrunner\\5.png','png')
            result6.writeToFile('D:\\python_file\\monkeyrunner\\6.png','png')
            result7.writeToFile('D:\\python_file\\monkeyrunner\\7.png','png')
            result8.writeToFile('D:\\python_file\\monkeyrunner\\8.png','png')
            result9.writeToFile('D:\\python_file\\monkeyrunner\\9.png','png')

            code1=os.popen("python D:\python_file\ocr_test\png_1.py")
            code2=os.popen("python D:\python_file\ocr_test\png_2.py")
            code3=os.popen("python D:\python_file\ocr_test\png_3.py")
            code4=os.popen("python D:\python_file\ocr_test\png_4.py")
            code5=os.popen("python D:\python_file\ocr_test\png_5.py")
            code6=os.popen("python D:\python_file\ocr_test\png_6.py")
            code7=os.popen("python D:\python_file\ocr_test\png_7.py")
            code8=os.popen("python D:\python_file\ocr_test\png_8.py")
            code9=os.popen("python D:\python_file\ocr_test\png_9.py")




            print(code1.read())
            print(code2.read())
            print(code3.read())
            print(code4.read())
            print(code5.read())
            print(code6.read())
            print(code7.read())
            print(code8.read())
            print(code9.read())
            print('######################')




            
